﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Rotempco.Website.UserControls
{
    public class HyperLinkButtonConfirm : System.Web.UI.WebControls.HyperLink
    {
        private bool confirm = false;
        private string confirmMessage;

        public HyperLinkButtonConfirm()
            : base()
        {
        }

        public bool Confirm
        {
            set
            {
                confirm = value;
            }

            get
            {
                return confirm;
            }
        }

        public string ConfirmMessage
        {
            set
            {
                confirmMessage = value;
            }

            get
            {
                return confirmMessage;
            }
        }

        public string SetArgument
        {
            set
            {
                confirmMessage += " " + value;
            }
        }

        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            if (this.Confirm)
            {
                if (confirmMessage != null)
                {
                    this.Attributes.Add("onClick", "return confirm('" + ConfirmMessage + "')");
                }
                else
                {
                    throw new ArgumentNullException("If you want there to be a confirm you need a confirm-message");
                }
            }

            base.Render(writer);
        }

    }
}